<?php

class Welcome extends Controller {
        private $after_welcome_url = 'welcome';
	function Welcome()
	{
		parent::Controller();
                $this->load->model('publication_model');
	}
	function index_(){
            redirect(site_url($this->after_welcome_url));
        }
	function index()
	{
		$where = NULL;
		$data['search'] = 'title or publisher';
                $data['area'] ='';
		if($this->input->get('Search') || $this->input->get('thematicArea'))
		{
			$data['search'] = $search = $this->input->get('Search');
			$data['area'] = $area_id = $this->input->get('thematicArea');
			
			$con = '';
			if(is_numeric($area_id))
			{
				$where = '(category_id = '.$area_id.' or sub_category_id = '.$area_id.')';
				$con = ' and ';
			}
			if($search != 'title or publisher')
			{
				$where.= $con.'(title like "%'.$search.'%" or publisher like "%'.$search.'%")';	
			}
			
		}
			$data['total_publications'] = $this->publication_model->total_publications($where);
			create_pagination($data['total_publications'], 3, config_item('per_page'));
			$data['publications'] = $this->publication_model->get_publications(config_item('per_page'), $this->uri->segment(3), $where);

		//debug_array($data);die();
		$data['page_title']	= 'Publications';
		$data['page'] = 'publication_list_welcome';
		
		$data['categories'] = $this->general_db_model->getAll('tbl_publication_category', 'category_name', 'parent_id = 0');
		//debug_array($data['categories']);die();
		$this->load->view('main', $data);		
	}
        
        function details($id)
	{
            $this->load->model('borrower_model');
            $data['publication'] = $this->publication_model->get_publication_detail($id);
            $data['publicationBorrowerList']=$this->borrower_model->get_active_borrower_list($id);
            $data['page_title']	= 'Publication Details';
            $data['page'] = 'publication_detail_welcome';
            $this->load->view('main', $data);
	}
}